package com.windoent.yugioh.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.windoent.yugioh.R;
import com.windoent.yugioh.utils.TDevice;

/**
 * 作者：Android
 * 时间：2022/1/16 11:08
 * 功能：繼承Dialog，自定义更新Dialog
 */
public class SeasonRewardDialog extends Dialog {

    private TextView mTvGetReward;
    private LinearLayout mLlDelete;


    private String titleStr;//从外界设置的title文本

    private onGetRewardOnclickListener listener;//确定按钮被点击了的监听器

    public void setOnclickListener(onGetRewardOnclickListener getRewardOnclickListener) {
        this.listener = getRewardOnclickListener;
    }

    public SeasonRewardDialog(Context context) {
        super(context, R.style.MoHUDialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.free_season_reward_dialog_layout);
        //按空白处能取消动画
        setCanceledOnTouchOutside(true);
        Window window = getWindow();
        WindowManager.LayoutParams attributes = window.getAttributes();
        attributes.gravity = Gravity.CENTER;
        attributes.width = ViewGroup.LayoutParams.WRAP_CONTENT;
        attributes.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        window.setGravity(Gravity.CENTER);
        window.setAttributes(attributes);

        //初始化界面控件
        initView();
        //初始化界面数据
        initData();
        //初始化界面控件的事件
        initEvent();

    }

    /**
     * 初始化界面的确定和取消监听器
     */
    private void initEvent() {
        mTvGetReward.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onGetRewardClick();
                    dismiss();
                }
            }
        });
        mLlDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
    }

    /**
     * 初始化界面控件的显示数据
     */
    private void initData() {
        //如果用户自定了title和message
        if (titleStr != null) {
            mTvGetReward.setText(titleStr);
        }

    }

    /**
     * 初始化界面控件
     */
    private void initView() {

        mTvGetReward = (TextView) findViewById(R.id.tv_get_reward);
        mLlDelete = (LinearLayout) findViewById(R.id.ll_delete);

    }

    /**
     * 从外界Activity为Dialog设置标题
     *
     * @param title
     */
    public void setTitle(String title) {
        titleStr = title;
    }


    public interface onGetRewardOnclickListener {
        public void onGetRewardClick();
    }

}
